

{% extends 'app01/base_backend.html' %}
  {% block person_manage %}
             <a class="navbar-brand" href="#">学生管理</a>
            {% endblock %}
{% block all_li %}
    <li role="presentation" class="active">
        <a href="#home" aria-controls="home" role="tab"data-toggle="tab">学生管理</a></li>
     <li role="presentation" class="active">
             <a href="{% url 'app01_backend' %}" style="color: #337ab7">返回个人管理</a></li>
{% endblock %}

{% block all_content %}

        {% block suibi %}
            <!--文章收藏显示页面-->
            <div class="panel panel-default">
        <div class="panel-heading">学生管理</div>
        <div class="panel-body">
            <table class="table-hover table table-hover">
                <thead>
                <tr>
                    <th>学号</th>
                    <th>姓名</th>
                    <th>班级</th>
                    <th>邮箱</th>
                    <th>手机</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {% for student in c_page %}
                    <tr>
                        <td>{{ student.username }}</td>
                        <td>{{ student.username }}</td>
                        <td>{{ student.stu_class }}</td>
                        <td>{{ student.email }}</td>
                        <td>{{ student.phone }}</td>
                        {% if student.limit %}
                            <td><a href="#" style="color: rgba(83,143,232,0.74)" type="button" class="relax_btn"
                                   relax_id="{{ student.id }}">解除禁言</a></td>
                        {% else %}
                            <td><a href="#" style="color: rgba(80,208,163,0.74)" type="button" class="limit_btn"
                                   limit_id="{{ student.id }}">设置禁言</a></td>

                        {% endif %}


                    </tr>

                {% endfor %}

                </tbody>
            </table>
        </div>
    </div>
    {# 分页显示 #}
    <div class="pager">
        <nav aria-label="Page navigation">
            <ul class="pagination">
                {{ page_html }}
            </ul>
        </nav>
    </div>


        {% endblock %}

{% endblock %}




{% block js %}

    <script>
        if('{{ request.user.username }}'.slice(0,3)==='512'){
         $('#p_for_a').html('<a href="/app01/manage_student/" class="list-group-item">学生管理</a>')
        $('#role_for').html('角色：<br><a href="#">老师</a>')
    }


    if('{{ request.user.username }}'.slice(0,3)==='312'){

        $('#set_person_id').html('<p>班级：<input type="text" id="stu_class" class="form-control" value="{{ request.user.stu_class }}"></p>')
         $('#role_for').html('角色：<br><a href="#">学生</a>')
    }

 //设置禁言的事件
        $('.limit_btn').click(function () {
            let limit_id = $(this).attr('limit_id')
            $.ajax({
                url:'',
                type:'post',
                data:{'limit_id':limit_id,'op':1,'limit':''},
                success:function (array) {
                    if(array.code===100){
                        if(array.op===1){
                            alert('禁言成功')
                             window.location.reload()
                        }
                    }
                    else {
                        alert(array.msg)
                    }

                }
            })


        });

        //设置解除禁言的点击事件
        $('.relax_btn').click(function () {
            let relax_id=$(this).attr('relax_id')
            $.ajax({
                url:'',
                type:'post',
                //传递的数据格式是一样的，根据op来决定禁言或解除禁言
                data:{'limit_id':relax_id,'op':0,'limit':''},
                success:function (array) {
                    if(array.code===100){
                        if(array.op===0){
                            alert('解除禁言成功')
                        }

                        window.location.reload()
                    }else {
                        alert(array.msg)
                    }

                }
            })


        });

    </script>



{% endblock %}
